
//1.两数之和
class Solution {
public:
    vector<int> twoSum(vector<int>& nums, int target) {
        int n=nums.size();
        vector<pair<int,int>> tmp;
        for(int i=0;i<n;i++)
        tmp.push_back({nums[i],i});  //存储数据+下标
        sort(tmp.begin(),tmp.end());  //排序

        int left=0,right=n-1;
        while(left<right) 
        {
            while(left<right&&tmp[left].first+tmp[right].first<target) left++;  //left+right<target
            if(tmp[left].first+tmp[right].first==target) return {tmp[left].second,tmp[right].second};  //等于直接返回

            right--;  //大于情况，将最大值减小
        }
        return {-1,-1};
    }
};